package com.qiwo.bpm.service.impl;

import org.springframework.stereotype.Service;

import com.qiwo.bpm.dao.TypeDao;
import com.qiwo.bpm.domain.FlowType;
import com.qiwo.bpm.service.FlowTypeService;
import com.qiwo.common.base.CoreServiceImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 
 * <pre>
 * 流程类型
 * </pre>
 *  @author  chenwenchao
 *  @date 2021-04-01 16:37:07
 * <small> 2021-04-01 16:37:07 | chenwenchao</small>
 */
@Service
public class FlowTypeServiceImpl extends CoreServiceImpl<TypeDao, FlowType> implements FlowTypeService {

    @Override
    public List<FlowType> getAllParentFlowTypes(Integer demonTypeId) {
        List<FlowType> allList= baseMapper.selectList(null);
        FlowType demon = (FlowType)this.baseMapper.selectById(demonTypeId);
        List<FlowType> typeList = new ArrayList();
        findAllParent(allList,demon, typeList);
        return typeList;
    }
    private void findAllParent(List<FlowType> allList,FlowType demon, List<FlowType> typeList) {
        typeList.add(demon);
       List<FlowType> list=allList.stream().filter(f->f.getParentId().equals(demon.getId())).collect(Collectors.toList());
        if (list!= null&&list.size()>0) {
            for(FlowType flowType:list) {
                findAllParent(allList, flowType, typeList);
            }
        }
    }
}
